let util = {};
util.title = function(title) {
    title = title || '点点维';
    window.document.title = title;
};

/**
 * 获取时间函数
 * @returns {Array}
 */
util.getTime = function () {
    var timeList = [];
    var j = 0;
    for (var i = 0;i<24;i++) {
        j = i;
        if (i < 10) {
            var time1 = '0'+i+':'+'00';
            var time2 = '0'+i+':'+'30';
            timeList.push({label:time1,value:j * 2});
            timeList.push({label:time2,value:(j*2)+1});
        } else {
            var time3 = i+':'+'00';
            var time4 = i+':'+'30';
            timeList.push({label:time3,value:j * 2});
            timeList.push({label:time4,value:(j*2)+1});
        }
    }
    return timeList;
};

/**
 * 获取当前年月日函数
 * @returns {{nowYear: number, nowMonth: number, nowDay: number}}
 */
util.getNowDate = function () {
    var date = new Date();
    var nowYear = date.getFullYear();
    var nowMonth = date.getMonth()+1;
    var nowDay = date.getDate();
    var nowData = {
        nowYear: nowYear,
        nowMonth: nowMonth,
        nowDay: nowDay
    };
    return nowData;
};

/**
 * 获取当前时间的前两个月
 * @returns {{pastYear: number, pastMonth: number, pastDay: number}}
 */
util.getPastTwoMonths = function () {
    var date = new Date();
    //得到前两个月的
    date.setMonth(date.getMonth() - 2);
    var pastYear = date.getFullYear();
    var pastMonth = date.getMonth()+1;
    var pastDay = date.getDate();
    var pastData = {
        pastYear: pastYear,
        pastMonth: pastMonth,
        pastDay: pastDay
    };
    return pastData;
} ;

/**
 * 根据待办事项状态
 * 返回相应的提示字段
 * @param type
 * @param typeString
 * @param startTime
 * @returns {*}
 */
util.getTaskStateContent = function (type,typeString,startTime,uuid,userUuid,name,isReplaced) {
    var string;
    if (type === 'warning') {
        if (typeString === "待接单")
            string = "等待运维人员接单";
        if (typeString === "待处理")
            string = "预计处理时间为"+'<br/>'+"(" + startTime + ")";
        if (typeString === "挂起中")
            string = "运维人员正在努力修复故障";
        if (typeString === "处理中")
            string = "运维人员正在努力修复故障";
        if (typeString === "待评价")
            string = "本次维修已结束，"+'<br/>'+"请评价运维人员的服务质量";
        if (typeString === "已完成")
            string = "本次维修已完成";
        if (typeString === "已撤销")
            string = "你撤销了这个报修";
        if (typeString === "进行中") {
            if (userUuid === null || userUuid === '' || userUuid === undefined) {
                string = "待维修完成后，将信息补充完整";
            } else {
                if (uuid !== userUuid) {
                    string = name+"将该记录抄送给你";
                }
            }
        }
        if (typeString === "已完成")
            string = "维修单已完成";
    } else if (type === 'inspection') {
        if (typeString === '待接单')
            string = "等待运维人员接单";
        if (typeString === "待确认")
            string = "报告已生成，"+'<br/>'+"请尽快确认报告内容";
        if (typeString === "待处理")
            string = "预计处理时间为一周内";
        if (typeString === "待评价")
            string = "本次巡检已结束，"+'<br/>'+"请评价运维人员的服务质量";
        if (typeString === "已完成")
            string = "本次巡检已结束";
        if (typeString === "被退回")
            string = "等待运维人员重新生成报告"
    } else if (type === 'commodity') {
        if (typeString === "审批中" || typeString === "待审批")
            string = "等待领导审批";
        if (typeString === "待配送")
            string = "等待供应商配送";
        if (typeString === "配送中")
            string = "你采购的物品正在配送中";
        if (typeString === "待评价")
            string = "本次采购已结束"+'<br/>'+"请评价供应商的服务质量";
        if (typeString === "已完成")
            string = "本次采购已完成";
        if (typeString === "已撤销")
            string = "你撤销了这个采购流程";
        if (typeString === "已拒绝")
            string = "你的采购申请被拒绝了";
        if (typeString === "经办拒绝")
            string = "本次采购申请被拒绝了";
        if (typeString === "审批拒绝")
            string = "本次审批申请被拒绝了";
    } else if (type === 'voucher') {
        if (typeString === "配送中")
            string = "你采购的物品正在配送中";
        if (typeString === "待评价")
            string = "本次采购已结束，"+'<br/>'+"请评价供应商的服务质量";
        if (typeString === "已完成")
            string = "本次凭证请领已完成";
    } else if (type === 'message') {
        string = typeString;
    }

    return string;
};

util.getInspectionState= function (inspectionState) {
    var inspectionObj = new Object();
    var string;
    if (inspectionState === '00') {
        // string = "待分配";

    } else if (inspectionState === '01') {
        string = "待接单";
    } else if (inspectionState === '02') {
        string = "待处理";
    } else if (inspectionState === '10') {
        string = "处理中";
    } else if (inspectionState === '11') {
        string = "被退回";
    } else if (inspectionState === '20') {
        string = "待确认";
    } else if (inspectionState === '90') {
        string = "待评价";
    } else if (inspectionState === '98') {
        string = "已撤销";
    } else if (inspectionState === '99') {
        string = "已完成";
    }
    inspectionObj.state = inspectionState;
    inspectionObj.string = string;
};

util.getTaskState= function (taskState) {
    var taskObj = new Object();
    var string;
    if (taskState === '00') {
        string = "待接单";
    } else if (taskState === '01') {
        string = "待接单";
    } else if (taskState === '02') {
        string = "待处理";
    } else if (taskState === '04') {
        string = "处理中";
    } else if (taskState === '06') {
        string = "挂起中";
    } else if (taskState === '14') {
        string = "进行中";
    } else if (taskState === '97') {
        string = "已撤销";
    } else if (taskState === '98') {
        string = "待评价";
    } else if (taskState === '99') {
        string = "已完成";
    }
    taskObj.state = taskState;
    taskObj.string = string;
};

/**
 * 时间比较大小
 * 大： 返回true
 * 小： 返回false
 * @param firstTime
 * @param secondTime
 * @returns {boolean}
 */
util.compareTime = function (firstTime,secondTime) {
    var firstNewTime = firstTime.replace(/\-/g,"\/");//替换字符，变成标准格式
    var secondNewTime = secondTime.replace(/\-/g,"\/");//替换字符，变成标准格式
    var d1 = new Date(Date.parse(firstNewTime));
    var d2 = new Date(Date.parse(secondNewTime));
    console.log(d1);
    console.log(d2);
    if (d1 > d2) {
        console.log('d1 > d2');
        return true;
    } else {
        console.log('d1 <= d2');
        return false;
    }
};

/**
 * 时间截取函数
 * @param time
 * @returns {string}
 */
util.substringTime = function (time) {
    if (time === null || time === '' || time === undefined) {
        return '';
    } else {
        return time.substring(0,time.lastIndexOf(":"));
    }
}

export default util

